package Clothing.controller.customer;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import Clothing.bean.BaseResponse;
import Clothing.bean.request.customer.AddUserRequest;
import Clothing.bean.request.customer.DeleteUserRequest;
import Clothing.bean.request.customer.EditUserRequest;
import Clothing.bean.request.customer.GetUserListRequest;
import Clothing.bean.respose.customer.CustomerResponse;
import Clothing.service.customer.CustomerService;
import Clothing.util.ResultModel;

@Controller
@RequestMapping(value = "/Customer")
public class CustomerController {

    @Resource
    private CustomerService customerService;
    /**
     * 登录
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getUserList", method = RequestMethod.POST)
    public ResultModel getUserList(@RequestBody GetUserListRequest request) {
        ResultModel resultModel = new ResultModel();
        CustomerResponse response = new CustomerResponse();
        int result = customerService.getUserList(request,response);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;

    }
    
    /**
     * 新增用户
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public ResultModel addUser(@RequestBody AddUserRequest request) {
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = customerService.addUser(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;

    }
    
    /**
     * 修改用户信息
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/editUser", method = RequestMethod.POST)
    public ResultModel editUser(@RequestBody EditUserRequest request) {
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = customerService.editUser(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    /**
     * 删除用户
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteUser", method = RequestMethod.POST)
    public ResultModel deleteUser(@RequestBody DeleteUserRequest request) {
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        String userId = request.getUserId();
        int result = customerService.deleteUser(userId);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
}
